package com.htstar.ovms.enterprise.utils;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class DateXQ {
    /**
     * 获取当前星期
     */
    public static String XQ(){
            SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd");
            String[] weekDays = { "7","1", "2", "3", "4", "5","6" };
            Calendar cal = Calendar.getInstance();
            Date date;
            try {
                cal.setTime(new Date());
            } catch (Exception e) {
                e.printStackTrace();
            }
            //一周的第几天
            int w = cal.get(Calendar.DAY_OF_WEEK) - 1;
            if (w < 0)
                w = 0;
           return  weekDays[w];
    }
    /**
     * 获取当前时分秒
     */
    public static String sfm(){
        Date t = new Date();
        java.sql.Time sqlt = new java.sql.Time(t.getTime());
        return   sqlt.toString();
    }

    /**
     *
     * @param
     * @return 该毫秒数转换为 * days * hours * minutes * seconds 后的格式
     * @author fy.zhang
     */
    public static String formatDuring(long mss) {
        long days = mss / (60 * 60 * 24);
        long hours = (mss % (60 * 60 * 24)) / (60 * 60);
        long minutes = (mss % (60 * 60)) / (60);
        if (days != 0) {
            return days + "d " + hours + "h " + minutes + "min ";
        } else if (hours != 0) {
            return hours + "h " + minutes + "min ";
        } else if (minutes != 0) {
            return minutes + "min ";
        }else{
            return  " 0min ";
        }
    }
}
